//       https://ac.nowcoder.com/acm/contest/61570/B




#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    string s;
    cin >> s;
    int ans = 0x3f3f3f;
    for (char i = 'a'; i <= 'z'; i++)
    {
        int sum = 0;
        for (int j = 0; j < s.size(); j++)
            sum += min(abs(s[j] - i), 26 - abs(s[j] - i));
        ans = min(sum, ans);
    }

    cout << ans << endl;
    return 0;
}